//=============================================================================
/**
 *
 *	@file		d_hosaka_st.c
 *	@brief		保坂用デバッグソース 常駐
 *	@author		hosaka genya
 *	@data		2009.03.04
 *
 */
//=============================================================================
#ifdef PM_DEBUG

#include "common.h"

#include "system/lib_pack.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/fontproc.h"
#include "system/window.h"
#include "system/numfont.h"
#include "system/arc_util.h"
#include "system/snd_tool.h"
#include "system/snd_system.h"
#include "system/wipe.h"
#include "system/pm_overlay.h"

#include "savedata/phc_svdata.h"
#include "poketool/poke_tool.h"

#include "fld_bmp.h"
#include "fieldmap.h"
#include "fieldsys.h"
#include "fieldmap_work.h"

#include "field/eventflag.h"
#include "field/evwkdef.h"
#include "fielddata/script/saveflag.h"

#include "msgdata/msg_debug_hosaka.h"
#include "msgdata/msg.naix"

#include "system/touchpanel_draw.h"
#include "field_light.h"
#include "field_glb_state.h"
#include "talk_msg.h"

#include "savedata/zukanwork.h"

#include "application/museum.h"
#include "application/bug_select.h"
#include "application/phc_diary.h"

#include "d_hosaka.h"
#include "d_hosaka_local.h"

FS_EXTERN_OVERLAY( debug_hosaka );


//=============================================================================
/**
 *								外部公開関数
 */
//=============================================================================

//----------------------------------------------------------------------------
/**
 *	@brief	アプリケーション動作タスク
 *
 *	@param	TCB_PTR p_tcb
 *	@param	* p_work
 *
 *	@return
 */
//-----------------------------------------------------------------------------
void DebugHosaka_CallApplication( TCB_PTR p_tcb, void * p_work )
{
	DebugHosakaMenuMain( p_tcb, p_work );
}

//--------------------------------------------------------------
///	メインTCB 開放ワーク
//==============================================================
typedef struct {
	TCB_PTR p_main_tcb;
	int seq;
} MAIN_TCB_FREE_WORK;

//-----------------------------------------------------------------------------
/**
 *	@brief
 *
 *	@param	TCB_PTR p_tcb
 *	@param	work
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void MainTcbFree( TCB_PTR p_tcb, void* work )
{
	MAIN_TCB_FREE_WORK* wk = (MAIN_TCB_FREE_WORK*)work;

	switch( wk->seq )
	{
		case 0 :
			// 親TCBを削除
			if( wk->p_main_tcb )
			{
				TCB_Delete( wk->p_main_tcb );
			}

			Overlay_UnloadID( FS_OVERLAY_ID( debug_hosaka ) );

			// 自分を削除
			TCB_Delete( p_tcb );
			break;
	}

}

//-----------------------------------------------------------------------------
/**
 *	@brief	メインＴＣＢを開放してオーバーレイをunloadするTCB開始
 *
 *	@param	TCB_PTR p_tcb
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
void DebugHosaka_FreeTcbAndUnloadOverlay( TCB_PTR p_tcb )
{
	MAIN_TCB_FREE_WORK* wk;

	wk = sys_AllocMemory( HEAPID_BASE_DEBUG, sizeof(MAIN_TCB_FREE_WORK) );
	MI_CpuClear8( wk, sizeof(MAIN_TCB_FREE_WORK) );

	wk->p_main_tcb = p_tcb;

	TCB_Add(MainTcbFree, wk, 0);
}


#endif // PM_DEBUG